//
//  CZStatusRetweetView.swift
//  weiBo
//
//  Created by apple on 16/5/14.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit

class CZStatusRetweetView: UIView {
    
    //定义全局的约束
    var retweetViewBottom: Constraint?
    //接受外界传进来的数据
    var statusViewModel: CZStatusViewModel? {
        didSet{
            contentLabel.text = statusViewModel?.retweetContent
            //判断是否显示collectionView  视图
            //卸载约束
            retweetViewBottom?.uninstall()
            if let picurls = statusViewModel?.status?.retweeted_status?.pic_urls where picurls.count > 0 {
                pictureView.hidden = false
                pictureView.picUrls = picurls
                
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.retweetViewBottom = make.bottom.equalTo(pictureView).offset(StatusTableViewCellMargin).constraint
                })
            }else{
                pictureView.hidden = true
                self.snp_makeConstraints(closure: { (make) -> Void in
                    self.retweetViewBottom = make.bottom.equalTo(contentLabel).offset(StatusTableViewCellMargin).constraint
                })
            }
            
            
        }
  
    }
    //懒加载转发图片
    private lazy var pictureView: CZStatusPictureView = {
        let view = CZStatusPictureView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
    
    //懒加载转发微博内容
    private lazy var contentLabel: UILabel = {
        let label = UILabel(textColor: UIColor.grayColor(), fontSize: 15)
        label.numberOfLines = 0
        label.text = "哈哈"
        
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
    }
    
    private func setUpUI(){
        addSubview(contentLabel)
        addSubview(pictureView)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(self).offset(StatusTableViewCellMargin)
            make.top.equalTo(self).offset(StatusTableViewCellMargin)
            make.left.equalTo(self).offset(StatusTableViewCellMargin)
        }
        pictureView .snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusTableViewCellMargin)
            make.leading.equalTo(contentLabel)
        }
        
        
        self.snp_makeConstraints { (make) -> Void in
            self.retweetViewBottom = make.bottom.equalTo(pictureView).offset(StatusTableViewCellMargin).constraint
        }
    
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
